package com.kaifamiao.controller;

import com.kaifamiao.pojo.Doctor;
import com.kaifamiao.pojo.Patientinfo;
import com.kaifamiao.service.imp.DoctorService;
import com.kaifamiao.service.imp.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PatientController {
    @Autowired
    PatientService patientinfoService = null;
    //查找所有的患者信息
    @RequestMapping("patientinfofindall")
    public String findall(Model model){
        List<Patientinfo> patientinfolist = patientinfoService.PatientinfofindAll();
        System.out.println(patientinfolist);
        model.addAttribute("patientinfolist",patientinfolist);
        return "Patientinfohtml/findall";
    }
    //根据id查找患者信息
    @RequestMapping("patientinfoselectone/{myid}")
    public String selectone(Model model, @PathVariable("myid") int id) {
        Patientinfo one=patientinfoService.selectpatientinfo(id);
        model.addAttribute("one",one);
        return "Patientinfohtml/addshow";
    }
    //跳转到增加html
    @RequestMapping("patientinfoadd")
    public String add() {
        return "Patientinfohtml/add";
    }
    //增加用户
    @RequestMapping("patientinfodoadd")
    public String doadd(Model model,Patientinfo one) {
        int u=patientinfoService.addpatientinfo(one);
        model.addAttribute("one",u);
        return "Patientinfohtml/addshow";
    }
    //修改：根据id显示患者信息
    @RequestMapping("patientinfoedit/{myid}")
    public String edit(Model model,@PathVariable("myid") int id) {
        Patientinfo one=patientinfoService.selectpatientinfo(id);
        model.addAttribute("one",one);
        return "Patientinfohtml/edit";
    }
    //修改用户信息
    @RequestMapping("patientinfodoedit")
    public String doedit(Model model,Patientinfo one) {
        //在更新数据之前，把原数据取得
        Patientinfo old_one= patientinfoService.selectpatientinfo(one.getPatientid());
        one.setPatientid(old_one.getPatientid());
        one.setPatientgender(old_one.getPatientgender());
        one.setPatientpass(old_one.getPatientpass());
        one.setPatientidcard(old_one.getPatientidcard());
        one.setPatientgender(old_one.getPatientgender());
        one.setPatientpho(old_one.getPatientpho());
        int u=patientinfoService.updatepatientinfo(one);
        model.addAttribute("one",one);
        model.addAttribute("u",u);
        return "Patientinfohtml/edit";
    }
    //根据id删除用户信息
    @RequestMapping("patientinfodelete/{myid}")
    public String delete(Model model, @PathVariable("myid") int id) {
        Patientinfo one=patientinfoService.selectpatientinfo(id);
        model.addAttribute("one",one);
        int y=patientinfoService.deletepatientinfo(id);
        model.addAttribute("y",y);
        return "Patientinfohtml/editshow";
    }
//    患者总数
//    @RequestMapping("/selectPatientInfoCount")
//    public String selectPatientInfoCount(Model model){
//        int patient = patientinfoService.selectPatientInfoCount();
//        model.addAttribute("selectPatientInfoCount",patient);
//        return "Patientinfohtml/count";
//    }
}
